#include "GRefCounted.h"
#include "GError.h"

namespace GUtil
{
	GRefCounted::GRefCounted()
	{
	}

	GRefCounted::~GRefCounted()
	{
	
	}

	GUInt32 GRefCounted::GetRefCount() const
	{
		return RefCount.GetCount();
	}

	GUInt32 GRefCounted::GetLinkCount() const
	{
		return LinkCount.GetCount();
	}

	GUInt32	GRefCounted::RefIncrease()
	{
		return RefCount.Increment();
	}

	GUInt32	GRefCounted::RefDecrease()
	{
		if ((RefCount - 1) == (GUInt32)0)
		{
			GError::DebugCheck(LinkCount > 0, "Item being deleted is still linked");
			delete this;
		}

		return RefCount.Decrement();
	}
	
	GUInt32 GRefCounted::LinkIncrease()
	{
		return LinkCount.Increment();
	}
	
	GUInt32 GRefCounted::LinkDecrease()
	{
		return LinkCount.Decrement();
	}

	const GRefCounted& GRefCounted::operator = (const GRefCounted& Other)
	{
		// do not modify the ref count
		return *this;
	}

}; // namespace GUtil
